<?php
include "../include/global.php";
include "../include/admin_check.php";
include "../../FCKeditor/fckeditor.php";
$xtpl = new XTemplate ("configuration.htm");
//
include "../include/function.php";
$xtpl->assign("left_panel", left_panel());
$xtpl->assign("header_panel", header_panel());
$xtpl->assign("footer_panel", footer_panel());
// define language
if($lang=='e'){
	$configuration_id=2;
}else{
	$configuration_id=1;
}

$xtpl->assign("Configuration", Configuration);
$xtpl->assign("lbl_save", Save);
$xtpl->assign("lbl_companyname", CompanyName);
$xtpl->assign("lbl_tel", Tel);
$xtpl->assign("lbl_address", Address);

$xtpl->assign("lbl_destination", Destination);
$xtpl->assign("lbl_tour", Tour);
$xtpl->assign("lbl_hotel", Hotel);
$xtpl->assign("lbl_otherservice", OtherService);
$xtpl->assign("lbl_daytrip", Daytrip);
$xtpl->assign("lbl_home", Home);
$xtpl->assign("lbl_supportonline", SupportOnline);
$xtpl->assign("lbl_contactinformation", ContactInformation);
//
$path = "/media/logo/";

$image=$_FILES['configuration_bgdestination']['tmp_name'];
$image_name = $_FILES['configuration_bgdestination']['name'];	
$OldBgDestination=$_POST['OldBgDestination'];

$image2=$_FILES['configuration_bgtour']['tmp_name'];
$image_name2 = $_FILES['configuration_bgtour']['name'];	
$OldBgTour=$_POST['OldBgTour'];

$image3=$_FILES['configuration_bghotel']['tmp_name'];
$image_name3 = $_FILES['configuration_bghotel']['name'];	
$OldBgHotel=$_POST['OldBgHotel'];

$image4=$_FILES['configuration_bgother']['tmp_name'];
$image_name4 = $_FILES['configuration_bgother']['name'];	
$OldBgOther=$_POST['OldBgOther'];

$image5=$_FILES['configuration_bgdaytrip']['tmp_name'];
$image_name5 = $_FILES['configuration_bgdaytrip']['name'];	
$OldBgDaytrip=$_POST['OldBgDaytrip'];

$image6=$_FILES['configuration_bghome']['tmp_name'];
$image_name6 = $_FILES['configuration_bghome']['name'];	
$OldBgHome=$_POST['OldBgHome'];

$configuration_title=$_POST['configuration_title'];
$configuration_metakeyword=$_POST['configuration_metakeyword'];
$configuration_metadescription=$_POST['configuration_metadescription'];
$configuration_company=$_POST['configuration_company'];
$configuration_email=$_POST['configuration_email'];
$configuration_phone=$_POST['configuration_phone'];
$configuration_fax=$_POST['configuration_fax'];
$configuration_address=$_POST['configuration_address'];
$configuration_copyright=$_POST['configuration_copyright'];
$configuration_support=$_POST['configuration_support'];
$configuration_contact=$_POST['configuration_contact'];

$type=$_POST['type'];
$xtpl->assign("type", $type);

if($_GET['img']==1){
	$type = $_GET['type'];
	$stsql = "SELECT configuration_$type as bg FROM ".pre_table."configuration WHERE configuration_id='".$configuration_id."'";
	$rs_img = recordset($stsql);
	if($rs_img['bg']){
		$Image_del = deletefile(const_Web_Path.$path.$rs_img['bg']);
	}
	//
	$stsql = "UPDATE ".pre_table."configuration SET configuration_$type='' WHERE configuration_id='".$configuration_id."'";
	$rs = execSQL($stsql);
}

$sub_mit = $_POST['sub_mit'];
if($sub_mit=="yes"){
	if($image_name)
		 $ImageUpload = upload_to_server(const_Web_Path.$path,$image,$image_name,$OldBgDestination);
	else $ImageUpload = $OldBgDestination;	
	
	if($image_name2)
		 $ImageUpload2 = upload_to_server(const_Web_Path.$path,$image2,$image_name2,$OldBgTour);
	else $ImageUpload2 = $OldBgTour;	
	
	if($image_name3)
		 $ImageUpload3 = upload_to_server(const_Web_Path.$path,$image3,$image_name3,$OldBgHotel);
	else $ImageUpload3 = $OldBgHotel;	
	
	if($image_name4)
		 $ImageUpload4 = upload_to_server(const_Web_Path.$path,$image4,$image_name4,$OldBgOther);
	else $ImageUpload4 = $OldBgOther;	
	
	if($image_name5)
		 $ImageUpload5 = upload_to_server(const_Web_Path.$path,$image5,$image_name5,$OldBgDaytrip);
	else $ImageUpload5 = $OldBgDaytrip;	
		
	if($image_name6)
		 $ImageUpload6 = upload_to_server(const_Web_Path.$path,$image6,$image_name6,$OldBgHome);
	else $ImageUpload6 = $OldBgHome;	

	$sql="UPDATE ".pre_table."configuration SET 
				configuration_title='".formatData($configuration_title)."', 
				configuration_metakeyword='".$configuration_metakeyword."',
				configuration_metadescription='".$configuration_metadescription."',
				configuration_company='".formatData($configuration_company)."', 
				configuration_email='".formatData($configuration_email)."', 
				configuration_address='".formatData($configuration_address)."', 
				configuration_phone='".formatData($configuration_phone)."',	
				configuration_fax='".formatData($configuration_fax)."',	
				configuration_copyright='".formatData($configuration_copyright)."',	
				configuration_bgdestination='".$ImageUpload."',
				configuration_bgtour='".$ImageUpload2."',
				configuration_bghotel='".$ImageUpload3."',
				configuration_bgother='".$ImageUpload4."',
				configuration_bgdaytrip='".$ImageUpload5."',
				configuration_bghome='".$ImageUpload6."',
				configuration_support='".$configuration_support."',
				configuration_contact='".$configuration_contact."'
				WHERE configuration_id='".$configuration_id."'";			
	execSQL($sql);

	$xtpl->assign("successfully", redir("configuration.php", Successfully));
}else{
	$sql="select * from ".pre_table."configuration where configuration_id='".$configuration_id."'";
	$row=recordset($sql);
	
	$configuration_email=$row['configuration_email'];	
	$configuration_address=$row['configuration_address'];	
	$configuration_phone=$row['configuration_phone'];	
	$configuration_fax=$row['configuration_fax'];	
	$configuration_company=$row['configuration_company'];	
	$configuration_metakeyword=$row['configuration_metakeyword'];	
	$configuration_metadescription=$row['configuration_metadescription'];	
	$configuration_title=$row['configuration_title'];	
	$configuration_copyright=$row['configuration_copyright'];		
	
	$xtpl->assign("configuration_title", $configuration_title);
	$xtpl->assign("configuration_company", $configuration_company);
	$xtpl->assign("configuration_email", $configuration_email);
	$xtpl->assign("configuration_address", $configuration_address);
	$xtpl->assign("configuration_phone", $configuration_phone);
	$xtpl->assign("configuration_fax", $configuration_fax);
	$xtpl->assign("configuration_metakeyword", $configuration_metakeyword);
	$xtpl->assign("configuration_metadescription", $configuration_metadescription);
	$xtpl->assign("configuration_copyright", $configuration_copyright);
	
	$old_configuration_bgdestination = $row['configuration_bgdestination']; 
	if($old_configuration_bgdestination)
	{
		$has_bgdestination='<img src='.const_Web_Url.$path.'/'.$old_configuration_bgdestination.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bgdestination\')">Xóa</a>';
	}
	$xtpl->assign("has_bgdestination", $has_bgdestination);
	
	$old_configuration_bgtour = $row['configuration_bgtour']; 
	if($old_configuration_bgtour)
	{
		$has_bgtour='<img src='.const_Web_Url.$path.'/'.$old_configuration_bgtour.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bgtour\')">Xóa</a>';
	}
	$xtpl->assign("has_bgtour", $has_bgtour);
	
	$old_configuration_bghotel = $row['configuration_bghotel']; 
	if($old_configuration_bghotel)
	{
		$has_bghotel='<img src='.const_Web_Url.$path.'/'.$old_configuration_bghotel.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bghotel\')">Xóa</a>';
	}
	$xtpl->assign("has_bghotel", $has_bghotel);
	
	$old_configuration_bgother = $row['configuration_bgother']; 
	if($old_configuration_bgother)
	{
		$has_bgother='<img src='.const_Web_Url.$path.'/'.$old_configuration_bgother.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bgother\')">Xóa</a>';
	}
	$xtpl->assign("has_bgother", $has_bgother);
	
	$old_configuration_bgdaytrip = $row['configuration_bgdaytrip']; 
	if($old_configuration_bgdaytrip)
	{
		$has_bgdaytrip='<img src='.const_Web_Url.$path.'/'.$old_configuration_bgdaytrip.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bgdaytrip\')">Xóa</a>';
	}
	$xtpl->assign("has_bgdaytrip", $has_bgdaytrip);
	
	$old_configuration_bghome = $row['configuration_bghome']; 
	if($old_configuration_bghome)
	{
		$has_bghome='<img src='.const_Web_Url.$path.'/'.$old_configuration_bghome.' width="150" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:del_image(\'bghome\')">Xóa</a>';
	}
	$xtpl->assign("has_bghome", $has_bghome);	
	
	$xtpl->assign("old_configuration_bgdestination", $old_configuration_bgdestination);
	$xtpl->assign("old_configuration_bgtour", $old_configuration_bgtour);
	$xtpl->assign("old_configuration_bghotel", $old_configuration_bghotel);
	$xtpl->assign("old_configuration_bgother", $old_configuration_bgother);
	$xtpl->assign("old_configuration_bgdaytrip", $old_configuration_bgdaytrip);
	$xtpl->assign("old_configuration_bghome", $old_configuration_bghome);
	$xtpl->assign("type", "EDIT");	
}

$sBasePath="../../FCKeditor/"; 
$oFCKeditor = new FCKeditor('configuration_support') ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Value		= $row['configuration_support'] ;
$oFCKeditor->Width	= "80%" ;
$oFCKeditor->Height	= "300" ;

$oFCKeditor2 = new FCKeditor('configuration_contact') ;
$oFCKeditor2->BasePath	= $sBasePath ;
$oFCKeditor2->Value		= $row['configuration_contact'] ;
$oFCKeditor2->Width	= "80%" ;
$oFCKeditor2->Height = "300" ;
///////////////////
$xtpl->parse("MAIN");
eval("?".">".$xtpl->text("MAIN"));
?>